package com.tajiang.business.businesscount.util;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.widget.Toast;
import com.tajiang.business.common.constant.TJCst;
import com.tajiang.business.common.http.Api;
import java.io.File;

/**
 * @Title:
 * @Description: 实现TODO
 * @Copyright:Copyright (c) 2011
 * @version 1.0
 */
public class UploadFileTask extends AsyncTask<String, Void, String>{

	public static final String requestURL =  TJCst.BASE_URL +  Api.user_avatar;
	/**
	 *  可变长的输入参数，与AsyncTask.exucute()对应
	 */
	private  ProgressDialog pdialog;
	private  Activity context=null;
	public UploadFileTask(Activity ctx){
		this.context=ctx;
		pdialog=ProgressDialog.show(context, "正在加载...", "系统正在处理您的请求");
	}
	@Override
	protected void onPostExecute(String result) {
		// 返回HTML页面的内容
		pdialog.dismiss();
		if(UploadUtils.SUCCESS.equalsIgnoreCase(result)){
			Toast.makeText(context, "上传成功!",Toast.LENGTH_LONG ).show();
		}else{
			Toast.makeText(context, "上传失败!",Toast.LENGTH_LONG ).show();
		}
	}

	@Override
	protected void onPreExecute() {
	}

	@Override
	protected void onCancelled() {
		super.onCancelled();
	}

	@Override
	protected String doInBackground(String... params) {
		File file = new File(params[0]);
		return UploadUtils.uploadFile( file, requestURL);
	}
	@Override
	protected void onProgressUpdate(Void... values) {
	}


}